import TYPE from "../type";

function orderReducer(state = { list: [], total: 0 }, action) {
    state = JSON.parse(JSON.stringify(state));
    switch (action.type) {
        case TYPE.ADD_ORDER_ITEM:
            state.list.push(action.data)
            return state;
        case TYPE.DEL_ORDER_LIST:
            state.list = [];
            return state;
        case TYPE.COUNT_ORDER_TOTAL:
            state.list.forEach(item => {
                state.total += item.price * item.num
            })
            return state;
        case TYPE.INIT_ORDER_TOTAL:
            state.total = 0;
            return state;
        default:
            return state;
    }

}


export default orderReducer;